﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Marmat.Forms
{
    internal partial class AsyncHelperForm
    {
        private int current = 0;
        private readonly Pen pen;

        internal AsyncHelperForm()
        {

            // 此调用是设计器所必需的。
            this.InitializeComponent();

            // 在 InitializeComponent() 调用之后添加任何初始化。
            this.pen = new Pen(Color.FromArgb(83, 141, 199), 8f);
        }

        private void AsyncMethodForm_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(this.pen, new Rectangle(0, 0, this.Width, this.Height));
        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            int min = 1;
            int max = 6;
            this.Label1.Text = $"{this.Text}{new string('.', this.current)}";
            this.current += 1;
            if (this.current > max)
            {
                this.current = min;
            }
        }

        private void AsyncMethodForm_TextChanged(object sender, EventArgs e)
        {
            this.Label1.Text = this.Text + new string('.', this.current);
        }

        protected override bool ShowWithoutActivation => true;

        private void AsyncHelperForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.pen.Dispose();
        }
    }
}